package com.hub.realtime.resource;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hub.realtime.resource.dto.input.ApplicationQueryParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hub.realtime.common.annotation.Log;
import com.hub.realtime.common.core.controller.BaseController;
import com.hub.realtime.common.core.domain.AjaxResult;
import com.hub.realtime.common.enums.BusinessType;
import com.hub.realtime.resource.domain.ResApplication;
import com.hub.realtime.resource.service.IResApplicationService;
import com.hub.realtime.common.utils.poi.ExcelUtil;
import com.hub.realtime.common.core.page.TableDataInfo;

/**
 * 项目管理表Controller
 *
 * @author wupeng
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/resource/application")
public class ResApplicationController extends BaseController {
    @Autowired
    private IResApplicationService resApplicationService;

    /**
     * 查询项目管理表列表
     */
    @PreAuthorize("@ss.hasPermi('resource:application:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplicationQueryParam param) {
        Page<ResApplication> page = resApplicationService.list(param);
        return getDataTable(page.getRecords(),page.getTotal());
    }


    @GetMapping("/getAppList")
    public TableDataInfo getAppList() {
        List<ResApplication> list = resApplicationService.getAppList();
        return getDataTable(list,null);
    }

    /**
     * 导出项目管理表列表
     */
    @PreAuthorize("@ss.hasPermi('resource:application:export')")
    @Log(title = "项目管理表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplicationQueryParam param) {
        List<ResApplication> list = resApplicationService.list(param).getRecords();
        ExcelUtil<ResApplication> util = new ExcelUtil<ResApplication>(ResApplication.class);
        util.exportExcel(response, list, "项目管理表数据");
    }

    /**
     * 获取项目管理表详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:application:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(resApplicationService.getBaseMapper().selectById(id));
    }

    /**
     * 新增项目管理表
     */
    @PreAuthorize("@ss.hasPermi('resource:application:add')")
    @Log(title = "项目管理表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResApplication resApplication) {
        return toAjax(resApplicationService.saveInfo(resApplication));
    }

    /**
     * 修改项目管理表
     */
    @PreAuthorize("@ss.hasPermi('resource:application:edit')")
    @Log(title = "项目管理表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResApplication resApplication) {
        return toAjax(resApplicationService.saveInfo(resApplication));
    }

    /**
     * 删除项目管理表
     */
    @PreAuthorize("@ss.hasPermi('resource:application:remove')")
    @Log(title = "项目管理表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(resApplicationService.deleteInfos(ids));
    }
}
